import '../public.dart';

class BankCardApi {
  /// 解绑用户的银行卡
  /// /bankCard/unbindingByUser/{bankCardId}
  static Future<BaseResponse<void>> unbindingByUser(int bankCardId) async {
    final response = await HttpUtil().request(
      '/bankCard/unbindingByUser/$bankCardId',
      method: 'POST',
    );
    return BaseResponse<void>.fromJson(response);
  }

  /// 银行卡绑定到客户端用户
  /// /bankCard/bindToUser
  static Future<BaseResponse<void>> bindToUser(
    ClientUserBankDto request,
  ) async {
    final response = await HttpUtil().request(
      '/bankCard/bindToUser',
      method: 'POST',
      data: request.toJson(),
    );
    return BaseResponse<void>.fromJson(response);
  }

  /// 获取银卡种类列表
  /// /bankCard/getList
  /// 响应主体内容
  static Future<BaseResponse<List<SysBankCardTypeEntity>>> getList() async {
    final response = await HttpUtil().request(
      '/bankCard/getList',
      method: 'GET',
    );
    return BaseResponse<List<SysBankCardTypeEntity>>.fromJson(
      response,
      fromJsonT: (json) => (json as List)
          .map<SysBankCardTypeEntity>((e) => SysBankCardTypeEntity.fromJson(e))
          .toList(),
    );
  }

  /// 获取用户已绑定的银卡种类列表
  /// /bankCard/getListByUser
  /// 响应主体内容
  static Future<BaseResponse<List<WithdrawBankCardComboxDto>>>
  getListByUser() async {
    final response = await HttpUtil().request(
      '/bankCard/getListByUser',
      method: 'GET',
    );
    return BaseResponse<List<WithdrawBankCardComboxDto>>.fromJson(
      response,
      fromJsonT: (json) => (json as List)
          .map<WithdrawBankCardComboxDto>(
            (e) => WithdrawBankCardComboxDto.fromJson(e),
          )
          .toList(),
    );
  }
}
